## Example: A Goppa code [24,9,>=11]


from PyM import *

K = Zn(5)

(_,T) = polynomial_ring(K,'T')

(F,x) = extension(K,T**2-2,'x')

q = cardinal(F)

g = T**10

a = [element(j,F) for j in range(1,q)]

C = goppa(g,a)  

H = blow(H_(C),K)

k = len(a)-rank(H)

show('k = dim(C) =',k)

# Generating matrix
G = left_kernel(transpose(H))



# In fact, it can be seen that d = 12, by minimizing the weight 
# of all non-zero code vectors.
# The bound d_C >= degree(g)+1 = 11 is by the Goppa bound
# But acturally d<=12, as the vector z below has weight 12 
# and is a code vector. Now a straightforward minimization of
# the code vectors weight shows that there are no non-zero 
# code vectors of weight 11, and actually produces code words
# of weight 12, such as z

z = vec([0, 0, 0, 0, 4, 0, 0, 0, 0, 2, 0, 4, 4, 0, 4, 1, 1, 1, 1, 2, 0, 1, 1, 0],K)

show('wt(z) =',wt(z))

show(z*transpose(H))


## By the theory, C = BCH(w,11), w primitive for F

w = x+2 # is a primitive element of F
show('order(w) =', order(w))


C1 = BCH(w,11)

H1 = blow(H_(C1),K)

k1 = order(w)-rank(H1)

show('k1 = dim(C1) =',k1)


